from flask import Flask
from werkzeug.routing import BaseConverter

app=Flask(__name__)
# 1.编写自己的转换器类,继承BaseConverter
class MobileConverter(BaseConverter):
    # 2.重写regex类属性
    regex = r'1[3-9]\d{9}'
# 3.把自定义转换器添加到转换器字典中
app.url_map.converters['mobile'] = MobileConverter
# 4.使用
@app.route('/<mobile:phone>')
def index(phone):
    return 'phone is %s' % phone

if __name__ == '__main__':
    app.run(debug=True)